package com.yantong.service.impl;

import com.yantong.utils.PageUtils;
import com.yantong.pojo.InformationGZHTemplate;
import com.yantong.mapper.InformationGZHTemplateMapper;
import com.yantong.service.InformationGZHTemplateService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 公众号消息模版
 *
 * @author TaoHao
 * @date 2021/3/9 14:25
 */
@Service
public class InformationGZHTemplateServiceImpl implements InformationGZHTemplateService {
    @Autowired
    private InformationGZHTemplateMapper informationGZHTemplateMapper;

    @Override
    public PageUtils<InformationGZHTemplate> page(InformationGZHTemplate informationGZHTemplate, int offset, int limit) {
        PageUtils<InformationGZHTemplate> pageUtils = new PageUtils<>();
        int total = informationGZHTemplateMapper.queryCount(informationGZHTemplate);
        if (total > 0) {
            pageUtils.setTotal(total);
            List<InformationGZHTemplate> memberList = informationGZHTemplateMapper.queryList(informationGZHTemplate, new RowBounds(offset, limit));
            pageUtils.setRows(memberList);
        } else {
            pageUtils.setTotal(0);
            pageUtils.setRows(new ArrayList<>());
        }
        return pageUtils;
    }

    @Override
    public int insert(InformationGZHTemplate informationGZHTemplate) {
        return informationGZHTemplateMapper.insertSelective(informationGZHTemplate);
    }

    @Override
    public int update(InformationGZHTemplate informationGZHTemplate) {
        return informationGZHTemplateMapper.updateByPrimaryKeySelective(informationGZHTemplate);
    }

    @Override
    public InformationGZHTemplate findDetail(Long id) {
        return informationGZHTemplateMapper.findDetail(id);
    }
}
